package com.zh.yqbj.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.util.SaResult;
import com.zh.yqbj.VO.NoteVO;
import com.zh.yqbj.dto.NoteDTO;
import com.zh.yqbj.entity.Note;
import com.zh.yqbj.service.NoteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/note")
public class NoteController {
    @Autowired
    private NoteService noteService;

    /**
     * 查询具体笔记内容
     *
     * @param noteId
     * @return
     */
    @SaCheckLogin
    @GetMapping
    public SaResult getNote(@RequestParam String noteId) {
        NoteVO noteVO = noteService.getNote(noteId);
        return new SaResult(200, null, noteVO);
    }

    /**
     * 新增笔记
     *
     * @param noteDTO
     * @return
     */
    @SaCheckLogin
    @PostMapping
    public SaResult addNote(@RequestBody NoteDTO noteDTO) {
        noteService.saveNote(noteDTO);
        return new SaResult(200, "保存成功", null);
    }

    /**
     * 更新笔记 考虑修改空间
     *
     * @param noteDTO NoteDTO
     * @return
     */
    @PutMapping
    @SaCheckLogin
    public SaResult updateNote(@RequestBody NoteDTO noteDTO) {
        noteService.updateNote(noteDTO);
        return SaResult.ok("保存成功");
    }

    /**
     * 删除笔记 status 0 - 1
     *
     * @param noteId
     * @return
     */
    @SaCheckLogin
    @DeleteMapping("/delete")
    public SaResult deleteNote(@RequestParam String noteId) {
        noteService.deleteNote(noteId);
        return SaResult.ok("删除笔记成功");
    }

    @SaCheckLogin
    @PutMapping("/recycle")
    public SaResult recycleNote(@RequestParam String noteId) {
        noteService.recycleNote(noteId);
        return SaResult.ok("回收笔记成功");
    }

    /**
     * 永久删除笔记 status 1 - 2
     *
     * @param noteId
     * @return
     */
    @SaCheckLogin
    @DeleteMapping("/remove")
    public SaResult removeNote(@RequestParam String noteId) {
        noteService.removeNote(noteId);
        return SaResult.ok("彻底删除笔记");
    }
}
